package com.sebray.journal;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.TextBox;

public class TextBox2 extends TextBox implements CommandListener {

	private final Command save = new Command("Save", Command.OK, 0);
	private Journal journal;
	
	public TextBox2(String title, String text, int maxSize, int constraints, Journal aJournal) {
		super(title, text, maxSize, constraints);

		journal = aJournal;
		addCommand(save);
		setCommandListener(this);
	}
	
	public void commandAction(Command cmd, Displayable dis) {
		if (cmd == save) {			
			journal.saveEntry(getString());
			journal.notifyDestroyed();
		}
	}
}
